package com.pine.dcts.task.status;

import com.pine.dcts.entity.JobInfo;
import com.pine.dcts.service.JobService;
import com.pine.dcts.service.TaskRunnerCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiaoyuan
 * @create 2021/4/12 11:23
 **/
@Component
public class DefaultTaskStatusUpdator implements TaskStatusUpdator {
    @Autowired
    private JobService jobService;

    @Override
    public void update(TaskRunnerCallback callback) {
        System.out.println(String.format("任务%s更新状态为%s，消息为：%s", callback.getTaskMeta().getTaskId(), callback.getTaskStatus().getName(), callback.getMessage()));
        JobInfo jobInfo = new JobInfo();
        jobInfo.setId(Integer.valueOf(callback.getTaskMeta().getTaskId()));
        jobInfo.setStatus(callback.getTaskStatus().getValue());
        jobService.updateById(jobInfo);
    }
}
